﻿using System;
using com.youzu.warh.protocol;
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    [Category("Ggame/Liberty")]
    public class NpcReset : AIBaseNode
    {
        // 清除忽略敌人列表
        public BBParameter<bool> clearIgnoreTargets = false;
        // 清除当前锁定目标
        public BBParameter<bool> clearCurrentLockTarget = false;
        // 清除移动目标位置
        public BBParameter<bool> clearTargetTransformAndPosition = false;
        // 清除复仇目标
        public BBParameter<bool> clearRevengeTarget = false;
        // 清除可能目标
        public BBParameter<bool> clearPossibleTarget = false;
        // 清除丢失锁定目标时间戳
        public BBParameter<bool> clearLostLockTargetTimestamp = false;
        // 重置默认的NpcStatus
        public BBParameter<bool> resetDefaultNpcStatus = false;
        // 重置默认的NpcAnimate
        public BBParameter<bool> resetAimmingState = false;
        // 重置搜索
        public BBParameter<bool> resetSearch;
        // 重置所有动画Trigger
        public BBParameter<bool> resetAllAnimatorTrigger;
        // 重置是否允许切换当前锁定目标
        public BBParameter<bool> resetAllowSwitchTarget = false;

        protected override void OnExecute()
        {
            BattleAgent battleAgent = _entity.battleAgent;
            // 清除忽略敌人列表
            if (clearIgnoreTargets.value)
            {
                battleAgent.ignoreTargets.Clear();
            }
            // 清除当前锁定目标
            if (clearCurrentLockTarget.value)
            {
                battleAgent.currentLockTarget = null;
            }

            if (clearTargetTransformAndPosition.value)
            {
                ownerSystemBlackboard.parent.SetVariableValue("TargetTransform",null);
                ownerSystemBlackboard.parent.SetVariableValue("TargetPosition",Vector3.zero);
            }
            // 清除复仇目标
            if (clearRevengeTarget.value)
            {
                battleAgent.revengeTarget = null;
            }
            // 清除可能目标
            if (clearPossibleTarget.value)
            {
                battleAgent.possibleTarget = null;
            }
            // 清除丢失锁定目标时间戳
            if (clearLostLockTargetTimestamp.value)
            {
                battleAgent.lostLockTargetTimestamp = Time.time;
            }
            // 重置默认的NpcStatus
            if (resetDefaultNpcStatus.value)
            {
                _entity.data.npcStatus = _entity.data.defaultNpcStatus;
                LibertyAIUtils.OnResetDefaultStatus?.Invoke(_entity.data.uniqueId,_entity.data.defaultNpcStatus);
            }
            // 重置瞄准状态
            if (resetAimmingState.value)
            {
                _entity.viewer.animationAgent.EnterAimingState(AimingState.None);
            }
            // 重置搜索
            if (resetSearch.value)
            {
                ownerSystemBlackboard.parent.SetVariableValue("Search",false);
            }
            // 重置开火Trigger
            if (resetAllAnimatorTrigger.value)
            {
                _entity.viewer.animator.ResetTrigger("Fire");
            }
            // 重置是否允许切换当前锁定目标
            if (resetAllowSwitchTarget.value)
            {
                _entity.battleAgent.allowSwitchTarget = true;
            }
            
            EndAction(true);
        }
    }
}